﻿using DAL;
using MODEL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BLL
{
    /// <summary>
    /// 评分管理类
    /// </summary>
    class DoScore
    {
        DataClasses1DataContext ctx = new DataClasses1DataContext();
        /// <summary>
        /// 提交评分
        /// </summary>
        /// <param name="ID">评估表ID</param>
        /// <param name="scoreList">评分清单</param>
        /// <param name="openQuestionList">开放式问题回答</param>
        /// <param name="status">要提交的评估状态 1未评 2已评 3暂存</param>
        /// <returns></returns>
        int SubmitScore(int ID, List<Score> scoreList,List<OpenQuestions> openQuestionList, int status)
        {
            int re = 0;
            try
            {
                T_Feedback fb = ctx.T_Feedback.Single(p => p.ID == ID);
                fb.Score = JsonHepler.GetJsonString(scoreList);
                fb.OpenQuestions = JsonHepler.GetJsonString(openQuestionList);
                fb.Status = status;
                ctx.SubmitChanges();
                re = 1;
            }
            catch
            {
                re = 0;
                return re;
            }
                return re;
        }
        /// <summary>
        /// 获取问卷状态
        /// </summary>
        /// <param name="fb"></param>
        /// <returns></returns>
        int? GetFeedbackStatus(T_Feedback fb)
        {
            try
            {
                var a = ctx.T_Feedback.Single(p => p.Appraisee == fb.Appraisee && p.Assessor == fb.Assessor && p.ExpirationDate >= DateTime.Now).Status;
                return a;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
